import 'package:flutter/material.dart';
import 'package:star_author/config/ui_constant.dart';

///TabBar的代理
class SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  SliverAppBarDelegate(this._tabBar, {this.callback, this.extent = 55});

  final Widget _tabBar;
  final Function? callback;

  final double? extent;

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    if (shrinkOffset >= maxExtent || shrinkOffset == 0) {
      callback?.call(shrinkOffset);
    }
    return Container(
      child: _tabBar,
      color: shrinkOffset > 0 ? Colors.white : UIConstant.colorF8F8,
    );
  }

  @override
  double get maxExtent => extent!;

  @override
  double get minExtent => extent!;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return true;
  }
}
